package Thread;

import java.util.concurrent.*;

/**
 * FeatureTask 未来任务
 *
 */

public class FutureTask_Study {

    private volatile static int k = 0;

    public static void main(String[] args) {
        CallableThread callableThread = new CallableThread();

        FutureTask<Integer> futureTask = new FutureTask(callableThread);

        try {
            Thread thread = new Thread(futureTask, "threade");
            thread.start();
            Integer integer = futureTask.get();
            System.out.println(integer);

            System.out.println(Thread.currentThread().getName() + "执行完成");
        } catch (InterruptedException | ExecutionException ex) {
            ex.printStackTrace();
        }
    }


    static class CallableThread implements Callable<Integer> {


        @Override
        public Integer call() throws Exception {

            Thread.sleep(1000);
            for (int i = 0; i < 1000; i++) {
                k++;
            }
            return k;
        }
    }
}
